package com.crux.kafka2ch;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.http.server.reactive.ServerHttpRequest;
import org.springframework.web.server.WebFilter;

@Configuration
public class WebFluxConfig {
    @Bean
    public WebFilter contextPathWebFilter(@Value("${server.reactive.context-path}")
                                                  String contextPath) {
        return (exchange, chain) -> {
            ServerHttpRequest request = exchange.getRequest();
            return chain.filter(
                    exchange.mutate()
                            .request(request.mutate().contextPath(contextPath).build())
                            .build());
        };
    }
}
